package com.ray.controller;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ray.bean.DatatablesViewPageBean;
import com.ray.bean.FeedOrderDetailBean;
import com.ray.bean.WarehouseInOutDetailBean;
import com.ray.exception.ServiceException;
import com.ray.pojo.MyUser;
import com.ray.bean.WorkshopMaterialStockCountBean;
import com.ray.service.IssueNoteService;
import com.ray.util.RequestUtil;
import com.ray.util.ResponseUtil;
import com.ray.util.ReturnStringUtil;

/**
 * 发料单
* <p>Title: IsSueNoteController</p>  
* <p>Description: </p>  
* @author 李斌  
* @date 2018年9月4日
 */
@Controller
@RequestMapping("/issueNote")
public class IssueNoteController {
	
	@Autowired
	IssueNoteService issueNoteService;
	
	@RequestMapping("/{methodName}")
	@ResponseBody
	private Map<String, Object> shoppingMallController(HttpServletRequest request,HttpServletResponse response,
			@PathVariable("methodName") String methodName) throws NoSuchMethodException, SecurityException, IllegalAccessException {
		String methodNameMapping=urlMethodMappingMap.get(methodName);
		Map requestParamMap = RequestUtil.getRequestAllParam(request);
		requestParamMap.put("request", request);
		requestParamMap.put("response", response);
		Method targetMethod = issueNoteService.getClass().getMethod(methodNameMapping, Map.class);
		Object object=null;
		try {
			 object=targetMethod.invoke(issueNoteService, requestParamMap);
		}catch(InvocationTargetException e) {
			if(e.getCause().getClass()== IllegalArgumentException.class || e.getCause().getClass() ==ServiceException.class) {
				e.printStackTrace();
				Assert.notNull(null,e.getTargetException().getMessage());
			}else {
				e.printStackTrace();
				return ResponseUtil.ResponseError(ReturnStringUtil.ERROR);
			}
		}
		return ResponseUtil.ResponseResult(object);
	}
	
	/**
	 *  方法名和请求路径映射
	 */
	private static  Map<String, String> urlMethodMappingMap;
	static{
		//原有接口
		urlMethodMappingMap=new HashMap<String,String>();
		urlMethodMappingMap.put("getFeedMaterialData", "getFeedMaterialData");//查询可生成发料单的数据
		urlMethodMappingMap.put("getIssueNoteData", "getIssueData");//查询发料单
		urlMethodMappingMap.put("getIssueNoteDataByIds", "getIssueDataByIds");//查询发料单
		urlMethodMappingMap.put("getOrderInfoDetailByNotProduct", "getOrderInfoDetailByNotProduct");//获取那些没有生产的订单明细信息
		
	    //修改
		urlMethodMappingMap.put("getWorkShopWarehouseMaterialCount", "getWorkShopWarehouseMaterialCount");//获取车间仓库数量
		urlMethodMappingMap.put("manualIssue", "manualIssue");//手动发料
		urlMethodMappingMap.put("getWorkShopMaterialCount", "getWorkShopMaterialCount");//手动发料
		urlMethodMappingMap.put("getWorkShopMaterialCountPage", "getWorkShopMaterialCountPage");//获取车间物料库分页
	}
	
}
